package com.dayatang.ibank.application.impl;

import java.math.BigDecimal;
import java.util.List;

import com.dayatang.ibank.application.BankApplication;
import com.dayatang.ibank.domain.Account;
import com.dayatang.ibank.domain.FundTransferService;

public class BankApplicationImpl implements BankApplication {
	
	private FundTransferService fundTransferService;

	public FundTransferService getTransferService() {
		return fundTransferService;
	}

	public void setTransferService(FundTransferService fundTransferService) {
		this.fundTransferService = fundTransferService;
	}

	@Override
	public void deposit(Account account, BigDecimal amount) {
		account.deposit(amount);
	}

	@Override
	public void withdraw(Account account, BigDecimal amount) {
		account.withdraw(amount);
	}

	@Override
	public void transfer(Account fromAccount, Account toAccount,
			BigDecimal amount) {
		fundTransferService.transfer(fromAccount, toAccount, amount);
	}

	@Override
	public void createAccount(Account account) {
		account.save();
	}

	@Override
	public void disableAccount(Account account) {
		account.disable();
	}

	@Override
	public void enableAccount(Account account) {
		account.enable();
	}

	@Override
	public Account getAccount(Long id) {
		return Account.get(id);
	}

	@Override
	public Account getAccountBySerialNumber(String serialNumber) {
		return Account.getBySerialNumber(serialNumber);
	}

	@Override
	public List<Account> listAccounts() {
		return Account.findActive();
	}

}
